import 'package:flutter/material.dart';

class OverlayUtil{

   static OverlayEntry _overlayEntry;
   static OverlayState overlayState;


   static void showOverlay(BuildContext context) async {
    //获取OverlayState
     overlayState = Overlay.of(context);
    //创建OverlayEntry
     _overlayEntry = OverlayEntry(
       opaque: false,
        maintainState: true,
        builder: (BuildContext context) => Positioned(
          child: Center(
            child: CircularProgressIndicator(),
          ),
        ));
    //显示到屏幕上。
     WidgetsBinding.instance.addPostFrameCallback((_) => overlayState.insert(_overlayEntry));
  }


  static void hideOverlay(){
    _overlayEntry.remove();
  }

}